var a = require("../WxNotificationCenter/WxNotificationCenter.js"), t = getApp();

Component({
    properties: {
        itemData: {
            type: Object,
            value: {}
        },
        showAttention: {
            type: Boolean,
            value: !1
        },
        showDel: {
            type: Boolean,
            value: !1
        },
        showCity: {
            type: Boolean,
            value: !1
        },
        pageType: {
            type: Number,
            value: 0
        }
    },
    data: {},
    methods: {
        bindAvatarTap: function() {
            var a = this.data.itemData;
            t.util.navToUserHome(a.userAccessToken);
        },
        clickTeam: function(a) {
            var e = this.data.itemData.teamId;
            t.util.navToTeamHome(e);
        },
        bindBigImageTap: function(a) {
            for (var t = this.data.itemData, e = [], i = 0; i < t.images.length; i++) e[i] = t.images[i].bigImage;
            1 == t.images.length ? wx.previewImage({
                current: e[0],
                urls: e
            }) : wx.previewImage({
                current: a.currentTarget.dataset.image,
                urls: e
            });
        },
        clickDel: function(e) {
            var i, n = this.data.itemData;
            i = 0 == this.data.pageType ? t.url.deleteDynamic : t.url.deleteVideo, wx.showModal({
                title: "提示",
                content: "确定要删除此动态吗？",
                success: function(e) {
                    e.confirm && t.network.post({
                        url: i,
                        params: {
                            id: n.dynamicId
                        },
                        before: function() {
                            wx.showLoading({
                                title: "删除中"
                            });
                        },
                        success: function(e) {
                            1 == e.data.result ? (t.util.showToast("删除成功"), a.postNotificationName("DynamicMakeTopSuccess")) : t.util.showToast(e.data.message);
                        },
                        fail: function() {
                            t.util.showToast("删除失败");
                        },
                        complete: function() {
                            wx.hideLoading();
                        }
                    });
                }
            });
        },
        clickMakeTop: function(e) {
            var i, n = this.data.itemData;
            i = 0 == this.data.pageType ? t.url.dynamicFirst : t.url.videoFirst, t.network.post({
                url: i,
                params: {
                    dynamicId: n.dynamicId
                },
                before: function() {
                    wx.showLoading({
                        title: "置顶中"
                    });
                },
                success: function(e) {
                    1 == e.data.result ? (t.util.showToast("置顶成功"), a.postNotificationName("DynamicMakeTopSuccess")) : t.util.showToast(e.data.message);
                },
                fail: function() {
                    t.util.showToast("置顶失败");
                },
                complete: function() {
                    wx.hideLoading();
                }
            });
        },
        clickCancelTop: function(e) {
            var i, n = this.data.itemData;
            i = 0 == this.data.pageType ? t.url.dynamicCancelFirst : t.url.videoCancelFirst, 
            t.network.post({
                url: i,
                params: {
                    dynamicId: n.dynamicId
                },
                before: function() {
                    wx.showLoading({
                        title: "取消置顶中"
                    });
                },
                success: function(e) {
                    1 == e.data.result ? (t.util.showToast("取消置顶成功"), a.postNotificationName("DynamicMakeTopSuccess")) : t.util.showToast(e.data.message);
                },
                fail: function() {
                    t.util.showToast("取消置顶失败");
                },
                complete: function() {
                    wx.hideLoading();
                }
            });
        },
        bindZanTap: function() {
            if (t.util.isLoginModal()) {
                var a = this, e = a.data.itemData;
                1 == e.zan ? t.network.post({
                    url: t.url.hunyuCycleZan,
                    params: {
                        dynamicId: e.dynamicId,
                        zan: 0
                    },
                    before: function() {
                        var t = e.zanCount - 1;
                        a.setData({
                            "itemData.zan": 0,
                            "itemData.zanCount": t
                        });
                    },
                    success: function(i) {
                        if (1 == i.data.result) t.util.showToast("取消赞成功"); else {
                            t.util.showToast(i.data.message);
                            var n = e.zanCount + 1;
                            a.setData({
                                "itemData.zan": 1,
                                "itemData.zanCount": n
                            });
                        }
                    },
                    fail: function() {
                        t.util.showToast("取消赞失败");
                        var i = e.zanCount + 1;
                        a.setData({
                            "itemData.zan": 1,
                            "itemData.zanCount": i
                        });
                    },
                    complete: function() {}
                }) : t.network.post({
                    url: t.url.hunyuCycleZan,
                    params: {
                        dynamicId: e.dynamicId,
                        zan: 1
                    },
                    before: function() {
                        var t = e.zanCount + 1;
                        a.setData({
                            "itemData.zan": 1,
                            "itemData.zanCount": t
                        });
                    },
                    success: function(i) {
                        if (1 == i.data.result) t.util.showToast("赞成功"); else {
                            t.util.showToast(i.data.message);
                            var n = e.zanCount - 1;
                            a.setData({
                                "itemData.zan": 0,
                                "itemData.zanCount": n
                            });
                        }
                    },
                    fail: function() {
                        t.util.showToast("点赞失败");
                        var i = e.zanCount - 1;
                        a.setData({
                            "itemData.zan": 0,
                            "itemData.zanCount": i
                        });
                    },
                    complete: function() {}
                });
            }
        },
        bindVideoTap: function() {
            wx.navigateTo({
                url: "/pages/dynamicDetail/dynamicDetail?dynamicId=" + this.data.itemData.dynamicId + "&autoplay=true"
            });
        },
        bindItemTap: function() {
            wx.navigateTo({
                url: "/pages/dynamicDetail/dynamicDetail?dynamicId=" + this.data.itemData.dynamicId
            });
        }
    },
    created: function() {},
    attached: function() {},
    ready: function() {}
});